package com.atwork.wuhua.dialog;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.atwork.wuhua.R;

public class CenterEditTextDialog extends BaseDialog implements View.OnClickListener {
    private ImageView imgColos;
    private EditText edName;
    private TextView tvNo, tvYes;
    private OnEdDialogClick onEdDialogClick;
    private String title = "", leftTxt = "", rightTxt = "";
    private Context mContext;


    public CenterEditTextDialog(@NonNull Context context, final OnEdDialogClick onEdDialogClick) {
        super(context);
        this.onEdDialogClick = onEdDialogClick;
        mContext = context;
    }

    public CenterEditTextDialog(@NonNull Context context, String title, final OnEdDialogClick onEdDialogClick) {
        super(context);
        this.onEdDialogClick = onEdDialogClick;
        this.title = title;
        mContext = context;
    }

    public CenterEditTextDialog(@NonNull Context context, String title, String leftTxt, String rightTxt, final OnEdDialogClick onEdDialogClick) {
        super(context);
        this.onEdDialogClick = onEdDialogClick;
        this.title = title;
        this.leftTxt = leftTxt;
        this.rightTxt = rightTxt;
        mContext = context;
    }

    @Override
    public void setGravityType(int gravity) {
        super.setGravityType(gravity);
    }

    @Override
    public int intiLayout() {
        return R.layout.dialog_center_edittext;
    }

    @Override
    public void initView() {
        imgColos = this.findViewById(R.id.img_colos);
        edName = this.findViewById(R.id.ed_name);
        tvNo = this.findViewById(R.id.tv_no);
        tvYes = this.findViewById(R.id.tv_yes);
        this.setCanceledOnTouchOutside(true);
        imgColos.setOnClickListener(this);
        tvNo.setOnClickListener(this);
        tvYes.setOnClickListener(this);
        this.
                edName.setText(title);
        if (leftTxt.equals("隐藏")) {
            tvNo.setVisibility(View.GONE);

        } else {
            tvNo.setText(leftTxt.length() == 0 ? "取消" : leftTxt);
        }
        tvYes.setText(rightTxt.length() == 0 ? "确定" : rightTxt);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_colos:
                dismiss();
                break;
            case R.id.tv_no:
                dismiss();
                break;
            case R.id.tv_yes:
                onEdDialogClick.dialogClick(edName.getText().toString(), 0);
                dismiss();
                break;
        }
    }


}
